from math import sqrt
s=int(input("Введите четырехзначное число: "))
if s<1000 or s>9999: 
    print("0")
else:
    s1=s//1000
    s2=(s//100)%10
    s3=(s//10)%10
    s4=s%10
    s5=s1*10+s2
    s6=s5*10+s3
    s7=s2*10+s3
    s8=s7*10+s4
    s9=s3*10+s4
    massiv=[s,s1,s2,s3,s4,s5,s6,s7,s8,s9]
    prime_lst=[]
    for sss in massiv:
        prime=True
        i=2
        while i<=sqrt(sss):
            if sss%i==0:
                prime=False
                break
            i+=1
        if prime:
            prime_lst.append(sss)
    if len(prime_lst)==0:
        print(0)
    else:    
        prime_lst=sorted(prime_lst)
        print(prime_lst[-1])